<!--
******************************************************************************************
''
''  警告: 本電腦程式著作受著作權法及國際公約之保護。
''  未經授權擅自複製或散佈本電腦程式著作之全部或部分
''  ，將導致嚴厲的民事或刑事處份，且將被依法提起最大
''  範圍的追訴。
''
''  CopyRight (C) Galaxy Software Service
******************************************************************************************
***************************************************************************************************************************
<<請依個別狀況自行輸入以下各欄位資料>>
*程式代號：GSSobjClander30
*程式名稱：GSSobjClander30
*目    的：產生小月曆物件「內部使用」
*
*參數說明：
*傳回值  ：
*副作用  ：
*備   註 ：
*範   例 ：
*版本變更：
* xx. YYYY/MM/DD   VER     AUTHOR      COMMENTS
* === ==========   =====   =======     ==========
'   1. 2002/08/16  1.0     brenda_chen New Create
*
***************************************************************************************************************************
-->
<HTML>
<HEAD>
<TITLE>Dynamic Month Calendar</TITLE>
<META HTTP-EQUIV="Content-Type"CONTENT="text/html; charset=utf-8">
<Style type="text/CSS">
	.DayHeading {font-family: Trebuchet MS; font-size: 10pt; Background: #e0e0e0}
</Style>
<script language="VBScript">
Dim myMonth, myDay
Dim mblnSetDate
mblnSetDate=False
Sub prev_click()
	myNewMonth = curMonth-1
	If myNewMonth <= 0 Then
		myNewMonth = 12
		curYear=curYear-1
	End If
	curMonth=myNewMonth
	DrawCalendar
End Sub

Sub next_click()
	myNewMonth = curMonth+1
	If myNewMonth >= 13 Then
		myNewMonth = 1
		curYear=curYear+1
	End If
	curMonth=myNewMonth
	DrawCalendar
End Sub

'Routines that involve checking valid dates are written in VBScript.
function NewMonth(inDate)
	thisMonth = Month(inDate)
	myMonth = Month(inDate)
	thisYear = Year(inDate)
	NewMonth = true
	if curYear = thisYear then
		if curMonth = thisMonth then
			NewMonth = false
		else
			curYear = thisYear
			curMonth = thisMonth
			curDayCell = -1
			HiLiteCell = -1
		end if
	else
		curYear = thisYear
		curMonth = thisMonth
		curDayCell = -1
		HiLiteCell = -1
	end if
end function

function getStartDay()
	getStartDay = weekday(curMonth & "/1/" & curYear)
end function

sub public_SetMonth(inDate)
	if isDate(inDate) then
		if NewMonth(inDate) then
			DrawCalendar
		end if
	else
		'msgbox "Invalid Date!", 0, "Dynamic Month Calendar"
	end if
end sub

sub public_SetValue(inDate)
	if isDate(inDate) then
           		HiLiteDay()
	else
		'msgbox "Invalid Date!", 0, "Dynamic Month Calendar"
	end if
end sub

sub public_SetCalendar()
    If Not mblnSetDate Then 
        public_SetDay gstrToday, ""
        mblnSetDate = True
    End If
end sub
sub public_Clear()
	if isDate(curMonth & "/" & curYear) then
		DrawCalendar
	end if
end sub

dim nowdate
sub btnToday_OnClcik()
	public_SetDay gstrToday, ""
	nowdate=gstrToday
	call getdate
end sub

sub public_SetDay(inDate, inCaption)
	if isDate(inDate) then
		if NewMonth(inDate) then
			DrawCalendar
		end if
		if not gblnShowCal then exit sub
		thisDay = Day(inDate)
		setCell = getStartDay() - 1 + (thisDay - 1)

		if curDayCell = -1 then
			curDayCell = setCell
			HiLiteDay
      else
			curDayCell = setCell
			HiLiteDay
		end if
		SetDayCaption setCell, inCaption
	else
		'msgbox "Invalid Date!", 0, "Dynamic Month Calendar"
	end if
end sub

</script>
<script language="JScript">
//Routines that involve the dynamic building/accessing data from the calendar are written in JScript
//Initialize variables
var curYear = "";
var curMonth = "";
var curDayCell = -1;
var HiLiteCell = -1;
var months = new Array("1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月");
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,30, 31, 30, 31);
var days = new Array("日", "一", "二", "三", "四", "五", "六");
var cDayCell;
var cDayNum;
var cDayCap;
var gblnShowCal=true;
var gblnShowCboCal=true;
var gblnShowBtnToday=true;
var gstrCal_FORMAT='1';
var gstrCal_TYPE='null';
var gstrevent_OncboMonthClick='Y';
var gstrRtn_TYPE='1';	//1-YYYY/MM/DD 2-YYYY/MM
var gstrToday='';

function public_SetCalander(blnShowCal){
	if(typeof(blnShowCal)=='boolean') gblnShowCal=blnShowCal;
}
function public_SetCboCal(blnShowCboCal){
	if(typeof(blnShowCboCal)=='boolean') gblnShowCboCal=blnShowCboCal;
}
function public_SetBtnToday(blnShowBtnToday){
	if(typeof(blnShowBtnToday)=='boolean') gblnShowBtnToday=blnShowBtnToday;
}

function public_SetCal_FORMAT(strCal_FORMAT){
	if(typeof(strCal_FORMAT)=='string') gstrCal_FORMAT=strCal_FORMAT;
}

function public_get_Cal_FORMAT(){
	return gstrCal_FORMAT;
}

function public_SetCal_TYPE(strCal_TYPE){
	if(typeof(strCal_TYPE)=='string') gstrCal_TYPE=strCal_TYPE;
}

function public_get_Cal_TYPE(){
	return gstrCal_TYPE;
}

function public_SetToday(vstrToday){
	if(typeof(gstrToday)=='string') gstrToday=vstrToday;
}

function public_get_Today(){
	return gstrToday;
}

function public_Setevent_OncboMonthClick(str){
	if(typeof(str)=='string') gstrevent_OncboMonthClick=str;
}

function public_SetRTN_TYPE(str){
	if(typeof(str)=='string') gstrRtn_TYPE=str;
}

function public_get_RTN_TYPE(){
	return gstrRtn_TYPE;
}

function public_get_ISCboMonthON(){
	return gstrevent_OncboMonthClick;
}

function public_get_Month(){
	return curMonth;
}

function public_get_Year(){
		return curYear;
}

function getdate(){
  	window.external.raiseEvent("event_OnCalDayClick", nowdate);
}

function public_get_Day(){
	if (curDayCell == -1)
		return "";
	else
		return cDayNum(curDayCell).innerText;
}

function SetDayCaption(iCell, sCaption){
	cDayCap(iCell).innerText = sCaption;
}

function public_get_DayCaption(){
	if (curDayCell == -1)
		return "";
	else
		return cDayCap(curDayCell).innerText;
}

function getDays() {
	// Test for leap year when February is selected.
	if (2 == curMonth)
	   	return ((0 == curYear % 4) && (0 != (curYear % 100))) ||
			  (0 == curYear % 400) ? 29 : 28;
	else
		return daysInMonth[curMonth - 1];
}

function public_get_EndDay(intYear,intMonth) {
	// Test for leap year when February is selected.
	if (2 == intMonth)
	   	return ((0 == intYear % 4) && (0 != (intYear % 100))) ||
			  (0 == intYear % 400) ? 29 : 28;
	else
		return daysInMonth[intMonth - 1];
}

function DrawCalendar(){
	var t='';
	var strShowYear;

	if((gstrCal_TYPE=='')||(gstrCal_TYPE=='0')||(gstrCal_TYPE=='1')||(gstrCal_TYPE=='3')||(gstrCal_TYPE=='8')||(gstrCal_TYPE=='13')){
		gstrCal_TYPE='1';}
	else{
                gstrCal_TYPE='2';}
 
	if(gstrCal_TYPE=='1'){
		strShowYear=curYear;}
	else{
		strShowYear=curYear-1911;
		if(strShowYear.toString().length==2) strShowYear='0'+ strShowYear.toString();
		if(strShowYear.toString().length==1) strShowYear='00'+ strShowYear.toString();}
	
	if(gblnShowCal){
		t = t + "<table border=0 width='100%' height='10%' cellspacing=0 cellpadding=0><tr>";
		//LIGHTGREY
		t = t + "<td width='100%'><table border=0 width='100%'  height='10%' bgcolor='#6699cc' cellspacing=0 cellpadding=0 style='BORDER-BOTTOM: 1px darkgray solid;BORDER-TOP: darkgray solid thin; BORDER-LEFT: darkgray solid thin; BORDER-RIGHT: darkgray solid thin'><tr>";
	 	t = t + "<td width=10 align='left'><font face='Trebuchet MS' color='white'><strong><DIV ID=prev STYLE='cursor:hand'>&lt;&lt;</DIV></td>";
		t = t + "<td align='center'><font face='Trebuchet MS' color='white' style='font-size:12px;'>";
		t = t + strShowYear + "年 ";
		t = t + " ";
		t = t + months[curMonth - 1];
	 	t = t + "</strong></font></td>";
	     	t = t + "<td width=10 align='right'><font face='Trebuchet MS' color='white'><strong><DIV ID=next STYLE='cursor:hand'>&gt;&gt;</DIV></td></tr></table></td></tr></table>";
	   	
		t = t + "<table border=0 cols=7 rows=7 width=100% height=10% cellspacing=0 cellpadding=0 style='BORDER-BOTTOM: darkgray solid thin; BORDER-LEFT: darkgray solid thin; BORDER-RIGHT: darkgray solid thin'>";
		
		//Write out column headers Sun, Mon, ... Sat
		t = t + "<tr>";
		for (icol=0; icol<7; icol++){
			t = t + "<td width=14.25% height=10% align=center  valign=center STYLE='font-size:12px;border:gray 0px solid;' class=DayHeading><b>" + days[icol] + "</b></td>";
		}
		t = t + "</tr>";
		//Build grid for calendar days
		var firstcell = getStartDay() - 1;
		var lastday = getDays();
		iDay = 1;
		icol = 0; irow = 0;
		sDayNum = "";
		t = t + "<tr height=5% STYLE='cursor:hand'>";
		for (x=0; x<42; x++){
			if (x < firstcell)
				sDayNum = "";
			else if (iDay > lastday)
				sDayNum = "";
			else {
				sDayNum = iDay;
				iDay++;
			}
			t = t + "<td id=DayCell align=center width=14.25%  STYLE='border:gray 0px solid;font-family:Verdana;font-size:10px;background:white'><span id=DayNum>" + sDayNum + "</span><br>";
			t = t + "<span id=DayCap> </span></td>";
			icol++;
			if (icol == 7){
				icol = 0;
				t = t + "</tr>";
				irow++;
				if (irow == 6)
					break;
				else
					t = t + "<tr height=16.5% STYLE='cursor:hand'>";
			}
		}
		t = t + "</table>";
	}
	else{
		t = t + "<CENTER style='BORDER-BOTTOM: darkgray solid thin; BORDER-LEFT: darkgray solid thin; BORDER-RIGHT: darkgray solid thin;'></CENTER>"
		
	}
	if(gblnShowCboCal){
		t = t + "<CENTER style='BORDER-BOTTOM: darkgray solid thin; BORDER-LEFT: darkgray solid thin; BORDER-RIGHT: darkgray solid thin;'>";
		t = t + "<INPUT style='font-size:12px;' TYPE='BUTTON' VALUE='-' onclick=\"JavaScript:CtltxtYearVal(-1);\">";
		t = t + "<INPUT TYPE='TEXT' style='font-size:12px;border: none;' readonly size=4 name='txtYEAR' value=" + strShowYear;
		if(gstrCal_TYPE=='1') 
			t = t + " maxlength=4";
		else
			t = t + " maxlength=3";
		t = t + " onchange=\"JavaScript:CtltxtYearVal(0);\"  onkeypress=\"JavaScript:if ((window.event.keyCode<48) || (window.event.keyCode>57)) window.event.keyCode='';\">";
		t = t + "<INPUT style='font-size:12px;' TYPE='BUTTON' VALUE='+' onclick=\"JavaScript:CtltxtYearVal(1);\"> ";
		t = t + "<SELECT name=cboMonth STYLE='width:30%;font-size:12px;' value=" + curMonth + " onchange=\"JavaScript:CtltxtYearVal(0);\"></SELECT>";
		if(!gblnShowCal) t = t + " <input type='button' name='btnOK' value='Go' style='font-size:9px;' onclick=\"window.external.raiseEvent('event_OncboMonthClick',getDays());\">";
		t = t + "</CENTER>";
	}
	if(gblnShowBtnToday){
		t = t + "<CENTER style='BORDER-BOTTOM: darkgray solid thin; BORDER-LEFT: darkgray solid thin; BORDER-RIGHT: darkgray solid thin;'><BUTTON id='btnToday' style='width=50%;font-size:12px;cursor:hand'>今天</BUTTON></CENTER>"
	}
	calendar.innerHTML = '';
	calendar.innerHTML = t;
	if(gblnShowCboCal) CreateMonthOptions();
	//Assign collections
	cDayCell = document.all.item("DayCell");
	cDayNum = document.all.item("DayNum");
	cDayCap = document.all.item("DayCap");
}

function CreateMonthOptions(){
	var intcboMonth='';
	for (var i=0; i<months.length; i++){
		var newitem = document.createElement("OPTION");
		newitem.text = months[i];
		intcboMonth=parseInt(i)+parseInt(1)
		newitem.value = intcboMonth;
		cboMonth.options.add(newitem);}
	cboMonth.value=curMonth
}

function CtltxtYearVal(intAddYear){
	var intYear;
	if((gstrCal_TYPE=='')||(gstrCal_TYPE=='0')||(gstrCal_TYPE=='1')||(gstrCal_TYPE=='3')||(gstrCal_TYPE=='8')||(gstrCal_TYPE=='13')){ //YYYY
		intYear=parseInt(document.all.txtYEAR.value)+intAddYear
		if(intYear<0) intYear=0;
		document.all.txtYEAR.value=intYear;
	}
	else{
		for (var i=0;i<document.all.txtYEAR.value.length;i++){
			if(document.all.txtYEAR.value.substr(i,1).toString()!='0'){
				intYear=document.all.txtYEAR.value.substr(i,document.all.txtYEAR.value.length-i);
				break;}
			intYear=0;
		}
		intYear=parseInt(intYear)+intAddYear;
		if(intYear<0) intYear=0;
		document.all.txtYEAR.value=intYear;
		if(document.all.txtYEAR.value.length==2) document.all.txtYEAR.value='0' + document.all.txtYEAR.value;
		if(document.all.txtYEAR.value.length==1) document.all.txtYEAR.value='00' + document.all.txtYEAR.value;
		intYear=intYear+1911
	}
	if(parseInt(intYear)>9999) intYear=9999;
	curYear = intYear;
	curMonth = cboMonth.value;
	if(gblnShowCal) DrawCalendar();
}

function HiLiteDay(){
	if (curDayCell != HiLiteCell){
		if (HiLiteCell != -1)
			cDayCell(HiLiteCell).style.background = "white";
		HiLiteCell = curDayCell;
		cDayCell(HiLiteCell).style.background = "LightGrey";
	}
}

function CellClick(curcell){	
	if (cDayNum(curcell).innerText != ""){
		curDayCell = curcell;
		HiLiteDay();		
		window.external.raiseEvent("event_OnCalDayClick",curYear);		
	}
}

function DayCellClick() {
	if ("DayCell" == event.srcElement.id){
		for (i=0; i<42; i++)
			if (cDayCell(i) == event.srcElement){
				CellClick(i);
				break;
			}
	}
}
function DayNumClick() {
	if ("DayNum" == event.srcElement.id){
		for (i=0; i<42; i++)
			if (cDayNum(i) == event.srcElement){
				CellClick(i);
				break;
			}
	}
}
function DayCapClick() {
	if ("DayCap" == event.srcElement.id){
		for (i=0; i<42; i++)
			if (cDayCap(i) == event.srcElement){
				CellClick(i);
				break;
			}
	}
}

function CheckClick(){
//Traps the click events for anything I care about.
	if ("DayCell" == event.srcElement.id){
		DayCellClick();
		return;
	}
	if ("DayNum" == event.srcElement.id){
		DayNumClick();
		return;
	}
	if ("DayCap" == event.srcElement.id){
		DayCapClick();
		return;
	}
	if ("btnToday" == event.srcElement.id){
		btnToday_OnClcik();
		return;
	}
	if ("prev" == event.srcElement.id){
		prev_click();
		return;
	}
	if ("next" == event.srcElement.id){
		next_click();
		return;
	}
}
</script>
</HEAD>

<BODY BGColor="#F3F3F3"  TopMargin=0 leftmargin=0>
<div id=calendar></div>
<script language="JavaScript">
	document.onclick = CheckClick;
</script>
</BODY>
</HTML>
